package edu.zut.oop;

import java.time.LocalDate;

/**
 * 图书信息类
 */
public class Book {

    String number;
    String name;
    String type;
    double price;
    LocalDate publishDate;

    /**
     * this作为返回值，表示返回当前对象的一个引用
     * @return
     */
    public Book getBook(){
        this.number = "rj789456";
        this.name = "SpringCloud";
        this.price = 58.5;
        this.type = "微服务开发";
        return this;
    }


    public void tell(){
        //通过this关键字调用成员方法
        //say();
        this.say();
        System.out.println("type:" + type + ",price" + price);
    }

    public void say(){
        System.out.println("number:" + number + ",name:" + name);
    }



    public Book(){

    }

    /**
     * 通过有参构造完成属性的初始化
     * 有参构造的参数名称一般和属性名称一致，此时，局部变量名和全局变量（属性）名称重复，怎么区分？
     * 默认使用原则是就近原则
     * 为了区分，我们可以使用this关键字，指向我们要使用的是全局变量（属性）
     * @param number
     * @param name
     * @param type
     * @param price
     * @param publishDate
     */
    public Book(String number,String name,String type,double price,LocalDate publishDate){
        this.number = number;
        this.name = name;
        this.type = type;
        this.price = price;
        this.publishDate = publishDate;
    }

    public Book(String name,String type,double price,LocalDate publishDate){
        this.name = name;
        this.type = type;
        this.price = price;
        this.publishDate = publishDate;
    }



    public static void main(String[] args) {

        Book book = new Book();
        book.number = "rj159465";
        book.name = "Java基础";
        //.....

        /*
        空指针异常：type属性没有进行赋值，默认是null
        if (book.type.equals("计算机")){

        }*/

        Book book1 = new Book("rj556789","SpringBoot开发","软件开发类",58.5,LocalDate.now());
        book1.tell();

        Book book2 = new Book();
        book2 = book2.getBook();
        book2.tell();
    }

}